import { defineStore } from "pinia";
import { ref } from "vue";
import type Typings from "@/typings";

const useUserStore = defineStore(
  "userStore",
  () => {
    // 设置默认值才能被 $reset 重置
    const userInfo = ref<Partial<Typings.User.instacne>>({});
    const setUserInfo = async (data: Typings.User.instacne) => {
      userInfo.value = data;
    };

    return {
      userInfo,
      setUserInfo,
    };
  },
  {
    persist: {
      enabled: true,

      strategies: [
        {
          storage: sessionStorage,
          paths: ["userInfo"],
        },
      ],
    },
  } as any
);

export default useUserStore;
